package com.atguigu.practice;

public class test6 {
    public static void main(String[] args) {
    }
    public static int StrToInt(String str){
        StringBuilder sb=new StringBuilder();
        for(int i=1;i<str.length();i++) {
            char ch = str.charAt(i);
            if (!Character.isDigit(ch)) {
                return 0;
            }
        }
        if(str.charAt(0)=='+'||str.charAt(0)=='-'){
            for(int i=1;i<str.length();i++){
                sb.append(str.charAt(i));
            }
        }else{
            for(int i=0;i<str.length();i++){
                sb.append(str.charAt(i));
            }
        }
        int res=Integer.parseInt(sb.toString());
        if(str.charAt(0)=='-'){
            res*=(-1);
        }
        return res;
    }
}
